package com.skyolder.milkbee.service;

import com.skyolder.milkbee.domain.Area;
import com.skyolder.milkbee.repository.AreaRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.List;

/**
 * Service Implementation for managing Area.
 */
@Service
@Transactional
public class AreaService {

    private final Logger log = LoggerFactory.getLogger(AreaService.class);
    
    @Inject
    private AreaRepository areaRepository;

    /**
     * Save a area.
     *
     * @param area the entity to save
     * @return the persisted entity
     */
    public Area save(Area area) {
        log.debug("Request to save Area : {}", area);
        Area result = areaRepository.save(area);
        return result;
    }

    /**
     *  Get all the areas.
     *  
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Transactional(readOnly = true) 
    public Page<Area> findAll(Pageable pageable) {
        log.debug("Request to get all Areas");
        Page<Area> result = areaRepository.findAll(pageable);
        return result;
    }

    /**
     *  Get one area by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Transactional(readOnly = true) 
    public Area findOne(Long id) {
        log.debug("Request to get Area : {}", id);
        Area area = areaRepository.findOne(id);
        return area;
    }

    /**
     *  Delete the  area by id.
     *
     *  @param id the id of the entity
     */
    public void delete(Long id) {
        log.debug("Request to delete Area : {}", id);
        areaRepository.delete(id);
    }
    
	public List<Area> findByRankAndParent(int level,long parent) {
		// TODO Auto-generated method stub
		return areaRepository.findByRankAndParent(level,parent);
	}
}
